apiready = function() {
seajs.use(['../../V',"../../api","../../jquery","../../app","../../service","../../pop"],function(V,$api,$,$app,service,$pop){
	$app.ready();
	var vm = {
		el: '#search-list',
	  	data: {
	    	unionid: $api.getStorage("shop_unionid"),
	    	page: 1,
	    	keyword: '',
	    	list: [],
	    	have_data: true,
	    	data_more: true
	  	},
	  	methods:{
	  		init: function(){
	  			if(this.have_data){
	  				this.getList();
	  			}else{
	  				$app.toast("没有更多数据了！");
	  			}
	  		},
	  		getList: function(){
	  			var self = this;
	  			document.querySelector("#orderMySearch").style.display = 'none';
				$app.ajax(service.buyGetOrderList,{
					data: {
						values: {
							unionid: self.unionid,
							keyword: self.keyword,
							page: self.page
						}
					}
				},function (res) {
					//console.log("orderMy: "+JSON.stringify(res));
					if(res.code == 0){
						if(!self.data_more){
							self.list = [];
						}
						if(res.data.length > 0 && Array.isArray(res.data)){
							var data = res.data;
							for(var i=0; i < data.length; i++){
								self.list.push(data[i]);
							}
							self.page++;
						}
						self.data_more = true;
						self.have_data = res.data.length <= 0 ? false : true;
						document.querySelector("#orderMyNull").style.display = self.list.length <= 0 ? "block" :"none";
					}
				});
	  		},
	  		//--去详情
	  		goOrderDetail: function(et){
	  			var order_id = et.currentTarget.parentNode.dataset.orderid;
	  			var is_group = et.currentTarget.parentNode.dataset.group == '1' ? true : false;
				$app.openWin('buyOrderDetail',{
					order_id: order_id,
					is_group: is_group
				});
	  		},
	  		//--联系卖家
	  		contactSeller: function(et){
	  			var userinfo = JSON.parse(et.currentTarget.dataset.userinfo);
				$app.yz_chat(userinfo);
	  		}
	  	},
	  	mounted:function() {
	  		api.setStatusBarStyle({
				style: 'dark',
				color: ''
			});
			var self = this;
			function searchValue(){
				document.querySelector("#orderMySearch").style.display = 'none';
				self.have_data = true;
				self.data_more = false;
				self.page = 1;
				UIInput.value(function(ret) {
				    if (ret) {
						self.keyword = ret.msg || '';
				    	if(self.keyword == ''){
				    		$app.toast("请输入关键字！");
				    		return;
				    	}
				    	self.init();
				    }
				});
			}
			var goSearch = document.querySelector("#goSearch");
			var UIInput = api.require('UIInput');
			UIInput.open({
			    rect: {
			        x: 50,
			        y: 35,
			        w: api.winWidth - 100,
			        h: 30
			    },
			    styles: {
			        bgColor: '#f5f5f5',
			        size: 14,
			        color: '#333',
			        textIndex: '5px',
			        placeholder: {
			            color: '#ccc'
			        }
			    },
			    autoFocus: true,
			    maxRows: 1,
			    placeholder: '商品关键字|订单号|名字',
			    keyboardType: 'search',
			    fixedOn: api.frameName
			}, function(ret) {
			    if (ret.eventType == 'search') {
			    	searchValue();
			    }
			});
			//--搜索点击
	  		goSearch.addEventListener("click",function(){
	  			searchValue();
	  		});
	  		//--加载更多
			api.addEventListener({
				name: 'scrolltobottom',
				extra:{
					threshold: 0            //设置距离底部多少距离时触发，默认值为0，数字类型
				}
			}, function(ret, err){
				self.init();
			});
	  	},
	  	created: function(){

	  	}
	};
	var even = function() {}
	var newVue = new Vue(vm);
	even();
	// V.apiready(vm,even);
});
}
